import { Application } from 'egg';
import {
  indexRule,
  createRule,
  updateRule,
  destroyRule,
  createBulkRule
 } from '../validate/goods/marketGoods';

/**
 * 营销管理
 */
export default (app: Application) => {
  const { auth } = app.middleware;
  const {  jwt } = app;

  return {
    'goods.marketGoods.list': {
      method: 'GET',
      path: '/api/goods/marketGoods',
      options: {
        tags: ['market/list'],
        description: '营销列表',
        handler: app.controller.goods.marketGoods.list,
        middlewares: [jwt, auth('goods.market.list')],
        validate: indexRule,
      },
    },
    'goods.marketGoods.create': {
      method: 'POST',
      path: '/api/goods/marketGoods',
      options: {
        tags: ['market/create'],
        description: '创建营销',
        handler: app.controller.goods.marketGoods.create,
        middlewares: [jwt, auth('goods.market.create')],
        validate: createRule,
      },
    },
    'goods.marketGoods.update': {
      method: 'PUT',
      path: '/api/goods/marketGoods/:id',
      options: {
        tags: ['market/update'],
        description: '更新营销',
        handler: app.controller.goods.marketGoods.update,
        middlewares: [jwt, auth('goods.market.update')],
        validate: updateRule,
      },
    },
    'goods.marketGoods.destroy': {
      method: 'DELETE',
      path: '/api/goods/marketGoods/:id',
      options: {
        tags: ['market/delete'],
        description: '删除营销',
        handler: app.controller.goods.marketGoods.destroy,
        middlewares: [jwt, auth('goods.market.destroy')],
        validate: destroyRule,
      },
    },
    'goods.marketGoods.goods': {
      method: 'POST',
      path: '/api/goods/marketGoods/goods',
      options: {
        tags: ['market/goods'],
        description: '营销分类绑定商品',
        handler: app.controller.goods.marketGoods.addMarketGoods,
        middlewares: [jwt, auth('goods.market.addMarketGoods')],
        validate: createBulkRule,
      },
    },
  };
};
